//
//  LoginViewController.m
//  MELive
//
//  Created by 曹曹 on 2016/10/20.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "LoginViewController.h"
#import "LoginBacgroundPlayer.h"
#import "MainViewController.h"
#import "VenderLoginView.h"
#import "Masonry.h"

@interface LoginViewController ()

@property (nonatomic, strong) LoginBacgroundPlayer *loginPlayer;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpBackgroundVideo];
    [self setUpSubViews];
}

- (void)setUpBackgroundVideo {
    _loginPlayer = [[LoginBacgroundPlayer alloc] initWithUrlForResource:@"launch"
                                                                   type:@"mp4"
                                                                  frame:self.view.bounds];
    _loginPlayer.repeat = YES;
    [self.view.layer addSublayer:_loginPlayer.playerLayer];
}

- (void)setUpSubViews {
    UIButton *speedLogin = [UIButton buttonWithType:UIButtonTypeCustom];
    [speedLogin setTitle:@"快速登录" forState:UIControlStateNormal];
    speedLogin.layer.cornerRadius = 5;
    speedLogin.layer.borderColor = [UIColor whiteColor].CGColor;
    speedLogin.layer.borderWidth = 1;
    [speedLogin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [speedLogin addTarget:self
                   action:@selector(gotoMainVC)
         forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:speedLogin];
    
    [speedLogin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(-100);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(self.view.mas_width).multipliedBy(0.6);
    }];
    
    VenderLoginView *vender = [[VenderLoginView alloc] init];
    [self.view addSubview:vender];
    
    [vender mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(speedLogin.mas_top).mas_equalTo(-50);
        make.width.mas_equalTo(self.view).multipliedBy(0.8);
        make.height.mas_equalTo(70);
        make.centerX.mas_equalTo(self.view.mas_centerX);
    }];
    
    UILabel *venderLabel = [[UILabel alloc] init];
    venderLabel.text = @"使用以下方式登录";
    venderLabel.font = [UIFont systemFontOfSize:12];
    venderLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:venderLabel];
    [venderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(vender.mas_top).offset(-5);
        make.centerX.mas_equalTo(self.view.mas_centerX);
    }];
    
    UIImageView *logoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_logo"]];
    [self.view addSubview:logoImageView];
    [logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.view.mas_centerY).multipliedBy(5/8.0);
        make.width.mas_equalTo(self.view.mas_width).multipliedBy(0.4);
        make.height.mas_equalTo(logoImageView.mas_width).multipliedBy(111/152.0);
        make.centerX.mas_equalTo(self.view.mas_centerX);
    }];
}

- (void)gotoMainVC {
    MainViewController *mainVC = [[MainViewController alloc] init];
    [self presentViewController:mainVC animated:NO completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
